<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>天气案例_检测属性</title>
  <script src="../js/vue.js"></script>
</head>


<!-- 
  两种监听方式都可以
  可以监听计算属性
 -->

<body>

  <div id="root">
    <h1>今天的天气:{{info}}</h1>
    <button @click="isHot = !isHot">切换</button>
  </div>

  <script type="text/javascript">
    // 阻止vue启动的时候产生生产提示
    Vue.config.productionTip = false;

    const vm = new Vue({
      el: '#root',
      data: {
        isHot: true,
      },
      computed: {
        info() {
          return this.isHot ? '炎热' : '凉爽'
        },
      },
      // watch: {
      //   isHot: {
      //     // 初始化时执行一次
      //     immediate: true,
      //     handler(newVal, oldVal) {
      //       console.log(newVal, oldVal)
      //     }
      //   }
      // }
    })

    vm.$watch('isHot', {
      immediate: true,
      handler(newVal, oldVal) {
        console.log(newVal, oldVal)
      }
    })
  </script>

</body>

</html>